package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetmealDao;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    MemberDao memberDao;
    @Autowired
    OrderDao orderDao;
    @Autowired
    SetmealDao setmealDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //今天日期
        String todayDate = DateUtils.parseDate2String(new Date());
        //获取本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本周日日期
        String thisWeekSunday = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        //获取本月一号日期
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取本月最后一天日期
        String thisMonthLastDay = DateUtils.parseDate2String(DateUtils.getLastDay4ThisMonth());
        //统计日期
        String reportDate = todayDate;
        //今天新增会员数量
        long todayNewMember =  memberDao.findTodayNewMember(todayDate);
        //会员总数
        long totalMember = memberDao.findTotalMember();
        //本周新增会员
        long thisWeekNewMember = memberDao.findCountAfterByDate(thisWeekMonday);
        //本月新增会员
        long thisMonthNewMember = memberDao.findCountAfterByDate(thisMonthFirstDay);
        //今天预约数
        long todayOrderNumber = orderDao.findTodayOrderNumber(todayDate);
        //今天到诊数
        long todayVisitsNumber = orderDao.findtodayVisitsNumber(todayDate);
        //本周预约数
        long thisWeekOrderNumber = orderDao.findOrderNumberByDate(thisWeekMonday,thisWeekSunday);
        //本周到诊数
        long thisWeekVisitsNumber = orderDao.findVisitsNumberByDate(thisWeekMonday);
        //本月预约数
        long thisMonthOrderNumber = orderDao.findOrderNumberByDate(thisMonthFirstDay,thisMonthLastDay);
        //本月到诊数
        long thisMonthVisitsNumber = orderDao.findVisitsNumberByDate(thisMonthFirstDay);
        //热门套餐
        List<Map<String,Object>> mapList = setmealDao.findhotSetmeal();
        Map<String,Object> map = new HashMap<>();
        map.put("reportDate",reportDate);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",mapList);
        return map;
    }
}
